import React, { Component } from 'react'

// 7. 组件中导入 store
import store from './store/index'

export default class App extends Component {
  render() {
    console.log(store.getState().count);
    return (
      <div>
        {/* 8. 在组件中通过 store.getState() 获取全局状态 */}
        <h1>App --- {store.getState().count}</h1>

        <button onClick={()=>{
          // 调用 dispatch 进行值的修改
          store.dispatch({type: 'add'})
        }}>点击加 1</button>

        <button onClick={()=>{
            store.dispatch({type: 'reduce'})
        }}> 点击减 1 </button>

        <button onClick={()=>{
            store.dispatch({type: 'addNum', payload: 5})
        }}>点击加指定数</button>

        <button onClick={()=>{
            store.dispatch({type: 'reduceNum', payload: 7})
        }}>点击减指定数</button>

      </div>
    )
  }
}
